import datetime
import os.path
import sys

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager


# 创建一个浏览器对象

class Driver:
    driver = ""

    # 构造函数
    def __init__(self):
        options = webdriver.ChromeOptions()
        self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
        self.driver.implicitly_wait(5)

    # 进行屏幕截图
    def getScreenShot(self):
        # 先构建文件夹名字
        dirname = datetime.datetime.now().strftime("%Y-%m-%d")
        # 看看文件夹是否存在，不存在则创建
        if not os.path.exists("../images/" + dirname):
            os.mkdir("../images/" + dirname)
        # 构建出文件名
        filename = sys._getframe().f_back.f_code.co_name + "-" + datetime.datetime.now().strftime(
            "%Y-%m-%d-%H%M%S") + ".png"
        self.driver.save_screenshot("../images/" + dirname + "/" + filename)


oj_driver = Driver()
